/*    */ package xin.petstore.framework.orm.mybatis.paginator.dialect;
/*    */ 
/*    */ import com.eloancn.framework.orm.mybatis.paginator.domain.PageBounds;
/*    */ import org.apache.ibatis.mapping.MappedStatement;
/*    */ 
/*    */ public class SQLServer2005Dialect extends Dialect
/*    */ {
/*    */   public SQLServer2005Dialect(MappedStatement mappedStatement, Object parameterObject, PageBounds pageBounds)
/*    */   {
/* 16 */     super(mappedStatement, parameterObject, pageBounds);
/*    */   }
/*    */ 
/*    */   protected String getLimitString(String sql, String offsetName, int offset, String limitName, int limit)
/*    */   {
/* 38 */     StringBuffer pagingBuilder = new StringBuffer();
/* 39 */     String orderby = getOrderByPart(sql);
/* 40 */     String distinctStr = "";
/*    */ 
/* 42 */     String loweredString = sql.toLowerCase();
/* 43 */     String sqlPartString = sql;
/* 44 */     if (loweredString.trim().startsWith("select")) {
/* 45 */       int index = 6;
/* 46 */       if (loweredString.startsWith("select distinct")) {
/* 47 */         distinctStr = "DISTINCT ";
/* 48 */         index = 15;
/*    */       }
/* 50 */       sqlPartString = sqlPartString.substring(index);
/*    */     }
/* 52 */     pagingBuilder.append(sqlPartString);
/*    */ 
/* 55 */     if ((orderby == null) || (orderby.length() == 0)) {
/* 56 */       orderby = "ORDER BY CURRENT_TIMESTAMP";
/*    */     }
/*    */ 
/* 59 */     StringBuffer result = new StringBuffer();
/* 60 */     result.append("WITH query AS (SELECT ")
/* 61 */       .append(distinctStr)
/* 62 */       .append("TOP 100 PERCENT ")
/* 63 */       .append(" ROW_NUMBER() OVER (")
/* 64 */       .append(orderby)
/* 65 */       .append(") as __row_number__, ")
/* 66 */       .append(pagingBuilder)
/* 67 */       .append(") SELECT * FROM query WHERE __row_number__ > ? AND __row_number__ <= ?")
/* 68 */       .append(" ORDER BY __row_number__");
/* 69 */     setPageParameter(offsetName, Integer.valueOf(offset), Integer.class);
/* 70 */     setPageParameter("__offsetEnd", Integer.valueOf(offset + limit), Integer.class);
/* 71 */     return result.toString();
/*    */   }
/*    */ 
/*    */   static String getOrderByPart(String sql) {
/* 75 */     String loweredString = sql.toLowerCase();
/* 76 */     int orderByIndex = loweredString.indexOf("order by");
/* 77 */     if (orderByIndex != -1)
/*    */     {
/* 80 */       return sql.substring(orderByIndex);
/*    */     }
/* 82 */     return "";
/*    */   }
/*    */ }

/* Location:           C:\java代码反编译器\core-1.1.4.jar
 * Qualified Name:     com.eloancn.framework.orm.mybatis.paginator.dialect.SQLServer2005Dialect
 * JD-Core Version:    0.6.0
 */